package com.strive.village.config;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mybatis配置类
 */

@Configuration
@MapperScan("com.strive.village.mapper") // 接口扫描mapper文件存放的位置
public class MybatisPlusConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 防止全表更新插件
        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor()); // 针对的是update和delete操作
        // 载入分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); // 参数配置了数据源
        return interceptor;
    }

    /**
     * 防止分页插件出现问题
     *
     * @return
     */
    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return configuration -> configuration.setUseDeprecatedExecutor(false);
    }
}
